package com.example.jinzproduct.server.impl;
import com.example.commons.entity.UserRoleDO;
import com.example.jinzproduct.dao.UserRoleDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.jinzproduct.server.UserRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * </pre>
 *
 * <small> 2018年3月23日 | Aron</small>
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleDao, UserRoleDO> implements UserRoleService {

    @Override
    public List<Long> listRoleId(Serializable userId) {
        return baseMapper.listRoleId(userId);
    }

    @Override
    public List<String> selroleNameList(Long userId){
        return this.baseMapper.selroleNameList(userId);
    }

    @Override
    public Integer userRolenum(Long userId) {
        List<String> organizationNewsDOS = baseMapper.selroleNameList(userId);
        int is=0;
        for(String name1:organizationNewsDOS){
            if(name1.equals("订单审核专员")){
                is=2;
            }else if(name1.equals("订单发布专员")){
                is=1;
            }else if(name1.equals("金职仓库审核专员")){
                is=3;
            }else if(name1.equals("超级用户角色")){
                is=4;
                break;
            }else if(name1.equals("金英仓库审核专员")){
                is=5;
                break;
            }else if(name1.equals("市场一部管理员")){
                is=6;
                break;
            }else if(name1.equals("市场二部管理员")){
                is=7;
                break;
            }else if(name1.equals("市场一部")){
                is=8;
            }else if(name1.equals("市场二部")){
                is=9;
            }else if(name1.equals("财务审核发票")){
                is=10;
                break;
            }else if(name1.equals("管理员")){
                is=11;
                break;
            }else if (name1.equals("市场总监")){
                is=12;
                break;
            }
        }
        return is;
    }



    @Override
    public List<UserRoleDO> findByKv(Object... params) {
        if (params == null) {
            return new ArrayList<>();
        }
        return baseMapper.selectByMap(convertToMap(params));
    }

    public Map<String, Object> convertToMap(Object... params) {
        Map<String, Object> map = new HashMap<>();
        if (params == null) {
            return map;
        }
        for (int i = 0; i < params.length; i++) {
            if (i % 2 == 1 && params[i] != null && StringUtils.isNotBlank(params[i].toString())) {
                map.put((String) params[i - 1], params[i]);
            }
        }
        return map;
    }
}
